package com.cmft.filetransfer.controller;

import com.cmft.filetransfer.service.FileTransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * 文件传输控制器，提供API接口用于调试和手动触发文件传输
 */
@RestController
@RequestMapping("/api/fileTransfer")
public class FileTransferController {

    private final FileTransferService fileTransferService;

    @Autowired
    public FileTransferController(FileTransferService fileTransferService) {
        this.fileTransferService = fileTransferService;
    }

    /**
     * 手动触发文件传输，传输当日文件
     */
    @PostMapping("/today")
    public ResponseEntity<String> transferTodayFiles() {
        try {
            int transferredCount = fileTransferService.transferTodayFiles();
            return ResponseEntity.ok("成功传输 " + transferredCount + " 个文件");
        } catch (Exception e) {
            return ResponseEntity.badRequest().body("文件传输失败: " + e.getMessage());
        }
    }

    /**
     * 检查服务状态
     */
    @GetMapping("/status")
    public ResponseEntity<String> checkStatus() {
        return ResponseEntity.ok("文件传输服务运行正常");
    }
}
